<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>德智博接口测试</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="static/love/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="static/love/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="static/love/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="static/love/AdminLTE.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="static/love/blue.css">
    <!-- jsonFormater -->
    <link rel="stylesheet" href="static/love/jsonFormater.css">
    <!-- jQuery 2.2.3 -->
    <script src="static/love/jquery-2.2.3.min.js"></script>
    <!-- Bootstrap 3.3.6 -->
    <script src="static/love/bootstrap.min.js"></script>
    <script src="static/love/jsonFormater.js" type="text/javascript" charset="utf-8"></script>
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
</head>



<body style="margin-top: 20px;">

    <div class="col-xs-12">
        <div class="col-xs-7" id="leftmainbox">

            <div class="panel-group" id="group1">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <a data-toggle="collapse" href="#panel1" onclick="$('#first_url').val('user');"
                            data-parent="#group1"> 德智博接口</a>
                        <span class="pull-right" style="color:#808080;font-size:0.8em;">code：-2 登录超时 -1 缺少参数或不符 1 成功 0
                            失败</span>
                    </div>
                    <ul class="nav nav-stacked" id="constant" style="padding: 10px;">
                        <li>
                            <div class="input-group">
                                <span class="input-group-addon">接口地址</span>
                                <input type="text" id="main_url" value="" class="form-control input-sm"
                                    placeholder="接口地址">
                                <span class="input-group-btn"><button class="btn btn-default btn-sm" type="button"
                                        onclick="app.copy('#main_url')">复制</button></span>
                            </div>
                        </li>
                        <li>
                            <div class="input-group">
                                <span class="input-group-addon">用户Token</span>
                                <input type="text" id="current_token"
                                    value="MDAwMDAwMDAwML57h9mSltSomb16YcOfnJzHbKRhioGpobLNp7GBdniYsYiK3Ia3z2yHupupsYZ9Zg"
                                    class="form-control input-sm" placeholder="用户Token" name="token">
                                <span class="input-group-btn"><button class="btn btn-default btn-sm" type="button"
                                        onclick="app.copy('#current_token')">复制</button></span>
                            </div>
                        </li>
                    </ul>
                    <div id="panel1" class="panel-collapse collapse in">
                        <div class="panel-body">
                            <ul class="nav nav-tabs">
                                <li class="dropdown active">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">基础<b
                                            class="caret"></b></a>
                                    <ul class="dropdown-menu" role="menu">
                                        <li><a href="#token" data-url="/token/settoken" tabindex="-1"
                                                data-toggle="tab">验证token</a></li>
                                        <li class="divider"></li>
                                    </ul>
                                </li>
                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">绘本<b
                                            class="caret"></b></a>
                                    <ul class="dropdown-menu" role="menu">
                                        <li><a href="#noc" data-url="/draw/index" tabindex="-1"
                                                data-toggle="tab">绘本首页(ok)</a></li>
                                        <li><a href="#noc" data-url="/draw/selected" tabindex="-1"
                                                data-toggle="tab">优选列表-更多</a></li>
                                        <li><a href="#noc" data-url="/draw/freedraw" tabindex="-1"
                                                data-toggle="tab">体验列表-更多</a></li>
                                        <li><a href="#noc" data-url="/draw/cate" tabindex="-1"
                                                data-toggle="tab">绘本分类列表</a></li>
                                        <li><a href="#secate" data-url="/draw/secate" tabindex="-1"
                                                data-toggle="tab">查询绘本列表</a></li>
                                        <li><a href="#sedraw" data-url="/draw/sedraw" tabindex="-1"
                                                data-toggle="tab">查询绘本详情</a></li>
                                        <li><a href="#sedraw" data-url="/draw/audiolist" tabindex="-1"
                                                data-toggle="tab">音频列表</a></li>
                                        <li><a href="#noc" data-url="/integral/intedraw" tabindex="-1"
                                                data-toggle="tab">绘本积分商城列表</a></li>
                                        <li><a href="#intedraw" data-url="/integral/intefind" tabindex="-1"
                                                data-toggle="tab">绘本积分商城详情</a></li>
                                        <li><a href="#mydraw" data-url="/draw/mydraw" tabindex="-1"
                                                data-toggle="tab">我的绘本</a></li>
                                        <li><a href="#mydraw" data-url="/draw/drawhistory" tabindex="-1"
                                                data-toggle="tab">绘本历史</a></li>
                                        <li><a href="#likedraw" data-url="/draw/likedraw" tabindex="-1"
                                                data-toggle="tab">查询绘本模糊查询</a></li>
                                    </ul>
                                </li>
                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">轮播图<b
                                            class="caret"></b></a>
                                    <ul class="dropdown-menu" role="menu">
                                        <li><a href="#noc" data-url="/system/home_rotation" tabindex="-1"
                                                data-toggle="tab">首页轮播图</a></li>
                                        <li><a href="#noc" data-url="/system/book_rotation" tabindex="-1"
                                                data-toggle="tab">绘本页轮播图</a></li>
                                    </ul>
                                </li>

                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">我的<b
                                            class="caret"></b></a>
                                    <ul class="dropdown-menu" role="menu">
                                        <li><a href="#seclass" data-url="/user/seclass" tabindex="-1"
                                                data-toggle="tab">查询班级</a></li>
                                        <li><a href="#bindclass" data-url="/user/bindclass" tabindex="-1"
                                                data-toggle="tab">绑定班级</a></li>

                                    </ul>
                                </li>

                             
                            </ul>
                            <div class="tab-content">


                                <!-- 用户信息 -->
                                <div class="tab-pane fade in active" id="user_info" style="padding: 15px;">
                                    <h5>相关参数：</h5>
                                    <ul class="nav nav-stacked">
                                        <li>
                                            <div class="input-group">
                                                <span class="input-group-addon">Token</span>
                                                <input type="text" name="token" value="" class="form-control input-sm"
                                                    placeholder="Token">
                                                <span class="input-group-addon">type</span>
                                                <input type="text" name="type" value="" class="form-control input-sm"
                                                    placeholder="type">
                                                <span class="input-group-addon">user_id</span>
                                                <input type="text" name="user_id" value="" class="form-control input-sm"
                                                    placeholder="user_id">
                                                <span class="input-group-btn">
                                                    <button class="btn btn-default btn-sm" type="submit">提交请求</button>
                                                </span>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                                <!-- 分页条数 -->
                                <div class="tab-pane fade in" id="noc" style="padding: 15px;">
                                    <h5>相关参数：</h5>
                                    <ul class="nav nav-stacked">
                                        <li>
                                            <div class="input-group">
                                                <span class="input-group-addon">limit</span>
                                                <input type="text" name="limit" value="" class="form-control input-sm"
                                                    placeholder="每页多少条，不传为10">
                                                <span class="input-group-addon">page</span>
                                                <input type="text" name="page" value="" class="form-control input-sm"
                                                    placeholder="第几页，不穿默认第一页">
                                                <span class="input-group-btn">
                                                    <button class="btn btn-default btn-sm" type="submit">提交请求</button>
                                                </span>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                                <!-- 根据id查询绘本 -->
                                <div class="tab-pane fade in" id="secate" style="padding: 15px;">
                                    <h5>相关参数：</h5>
                                    <ul class="nav nav-stacked">
                                        <li>
                                            <div class="input-group">
                                                <span class="input-group-addon">limit</span>
                                                <input type="text" name="limit" value="" class="form-control input-sm"
                                                    placeholder="每页多少条，不传为10">
                                                <span class="input-group-addon">page</span>
                                                <input type="text" name="page" value="" class="form-control input-sm"
                                                    placeholder="第几页，不穿默认第一页">
                                                <span class="input-group-addon">id</span>
                                                <input type="text" name="id" value="" class="form-control input-sm"
                                                    placeholder="分类id">
                                                <span class="input-group-btn">
                                                    <button class="btn btn-default btn-sm" type="submit">提交请求</button>
                                                </span>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                                <!-- 查询绘本详情 -->
                                <div class="tab-pane fade in" id="sedraw" style="padding: 15px;">
                                    <h5>相关参数：</h5>
                                    <ul class="nav nav-stacked">
                                        <li>
                                            <div class="input-group">
                                                <span class="input-group-addon">id</span>
                                                <input type="text" name="id" value="" class="form-control input-sm"
                                                    placeholder="绘本id">
                                                <span class="input-group-btn">
                                                    <button class="btn btn-default btn-sm" type="submit">提交请求</button>
                                                </span>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                                <!-- 查询绘本模糊查询 -->
                                <div class="tab-pane fade in" id="likedraw" style="padding: 15px;">
                                    <h5>相关参数：</h5>
                                    <ul class="nav nav-stacked">
                                        <li>
                                            <div class="input-group">
                                                <span class="input-group-addon">like</span>
                                                <input type="text" name="like" value="" class="form-control input-sm"
                                                    placeholder="关键词">
                                                <span class="input-group-btn">
                                                    <button class="btn btn-default btn-sm" type="submit">提交请求</button>
                                                </span>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                                <!-- 查询班级 -->
                                <div class="tab-pane fade in" id="seclass" style="padding: 15px;">
                                    <h5>相关参数：</h5>
                                    <ul class="nav nav-stacked">
                                        <li>
                                            <div class="input-group">
                                                <span class="input-group-addon">class_id</span>
                                                <input type="text" name="class_id" value=""
                                                    class="form-control input-sm" placeholder="班级id">
                                                <span class="input-group-btn">
                                                    <button class="btn btn-default btn-sm" type="submit">提交请求</button>
                                                </span>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                                <!-- 绑定班级 -->
                                <div class="tab-pane fade in" id="bindclass" style="padding: 15px;">
                                    <h5>相关参数：</h5>
                                    <ul class="nav nav-stacked">
                                        <li>
                                            <div class="input-group">
                                                <span class="input-group-addon">class_id</span>
                                                <input type="text" name="class_id" value=""
                                                    class="form-control input-sm" placeholder="班级id">
                                                <span class="input-group-addon">user_id</span>
                                                <input type="text" name="user_id" value=""
                                                    class="form-control input-sm" placeholder="用户id">
                                                <span class="input-group-btn">
                                                    <button class="btn btn-default btn-sm" type="submit">提交请求</button>
                                                </span>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                                <!-- 我的绘本 -->
                                <div class="tab-pane fade in" id="mydraw" style="padding: 15px;">
                                    <h5>相关参数：</h5>
                                    <ul class="nav nav-stacked">
                                        <li>
                                            <div class="input-group">
                                                <span class="input-group-addon">user_id</span>
                                                <input type="text" name="user_id" value="" class="form-control input-sm"
                                                    placeholder="用户id">
                                                <span class="input-group-btn">
                                                    <button class="btn btn-default btn-sm" type="submit">提交请求</button>
                                                </span>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                                <!-- 查询绘本积分详情 -->
                                <div class="tab-pane fade in" id="intedraw" style="padding: 15px;">
                                    <h5>相关参数：</h5>
                                    <ul class="nav nav-stacked">
                                        <li>
                                            <div class="input-group">
                                                <span class="input-group-addon">draw_id</span>
                                                <input type="text" name="draw_id" value="" class="form-control input-sm"
                                                    placeholder="绘本id">
                                                <span class="input-group-addon">user_id</span>
                                                <input type="text" name="user_id" value="" class="form-control input-sm"
                                                    placeholder="用户id">
                                                <span class="input-group-btn">
                                                    <button class="btn btn-default btn-sm" type="submit">提交请求</button>
                                                </span>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>

        <div class="col-xs-5" id="rightmainbox">
            <div class="panel panel-default">
                <div class="panel-heading">
                    调试日志 <span class="badge pull-right" id="clearLog" style="cursor:pointer">清空</span>
                </div>
                <div class="panel-body" id="consolelog"
                    style="word-wrap:break-word;height:139px;max-height:139px;overflow: auto;color: #555555;">

                </div>
            </div>

            <div class="panel panel-default">
                <div class="panel-heading">
                    返回结果
                </div>
                <div class="panel-body" id="precanvas" style="word-wrap:break-word;max-height:500px;overflow: auto;">

                </div>
            </div>
        </div>
    </div>


    <script type="text/javascript">
        var app = {
            url: 'https://dzb.tszpz.cn/api'
        };
        // var socketUrl = "ws://redpacket.ubanger.com:2346";
        //var ws = new WebSocket(socketUrl);
        var jf = new JsonFormater({
            dom: '#precanvas',
            isCollapsible: false,
            /*是否控制*/
            quoteKeys: true,
            tabSize: 1
        });
        var format = function (json) {
            var options = {
                dom: '#precanvas',
                isCollapsible: false,
                quoteKeys: true,
                tabSize: 1
            };
            var jf = new JsonFormater(options);

            jf.doFormat(json);
        }

        app.copy = function (id) {
            if (window.clipboardData) {
                var str = $(id).val() || '';
                window.clipboardData.setData("Text", str);
            } else {
                var dom = document.getElementById(id.replace('#', ''));
                dom.select(); // 选择对象
                document.execCommand("Copy");
            }
        }

        app.now = function (time, type) {
            if (typeof (time) != 'undefined') {
                pDate = new Date(time * 1000);
                if (type == true) {
                    nDate = new Date();
                    return nDate.getFullYear() - pDate.getFullYear();
                }
                //time = pDate.getFullYear() + "-";
                time = ("00" + (pDate.getMonth() + 1)).slice(-2) + "-";
                time += ("00" + pDate.getDate()).slice(-2) + " ";
                time += ("00" + pDate.getHours()).slice(-2) + ":";
                time += ("00" + pDate.getMinutes()).slice(-2) + ":";
                time += ("00" + pDate.getSeconds()).slice(-2)
            } else {
                pDate = new Date();
                time = ("00" + pDate.getHours()).slice(-2) + ":";
                time += ("00" + pDate.getMinutes()).slice(-2) + ":";
                time += ("00" + pDate.getSeconds()).slice(-2)
            }
            return time;
        }


        app.postdata = function (callback) {
            var url = $('#main_url').val();
            var item = {};
            item['token'] = $('#current_token').val();
            $('.tab-content .active input').each(function (x) {
                var name = $(this).attr('name');
                if ($('.tab-content .active input[type="text"][name="' + name + '"]').length == 1) {
                    var str = $('.tab-content .active input[type="text"][name="' + name + '"]').val();
                    if (str.length > 0) item[name] = str;
                } else {
                    item[name] = [];
                    $('.tab-content .active input[type="text"][name="' + name + '"]').each(function (x) {
                        if ($(this).val().length > 0) item[name].push($(this).val());
                    });
                }
            });

            $('.tab-content .active select').each(function (x) {
                var name = $(this).attr('name');
                if ($(this).val().length > 0) item[name] = {
                    id: $(this).val(),
                    str: $(this).find('option:selected').text()
                };
            });

            $('#consolelog').prepend('[' + app.now() + '] <span class="jf-ObjectBrace">CLIENT</span> data:' + JSON
                .stringify(item) + '<br />');
            $('pre').html('等待响应...');
            $.ajax({
                type: 'POST',
                url: url,
                data: item,
                dataType: 'json',
                timeout: 30000,
                success: function (data, textStatus) {
                    $('#consolelog').prepend('[' + app.now() +
                        '] <span class="jf-PropertyName">SERVER</span> data:' + JSON.stringify(
                            data) + '<br />');
                    $('pre').html(format(data));
                    if (typeof (callback) == 'function') callback(data);

                    if (typeof (data.data) != 'undefined' && typeof (data.data.token) != 'undefined')
                        $('#current_token').val(data.data.token);

                },
                error: function (textStatus, errorThrown) {
                    $('pre').text(format(textStatus));
                }
            });
        }
        var now = function (time, type) {
            if (typeof (time) != 'undefined') {
                pDate = new Date(time * 1000);
                if (type == true) {
                    nDate = new Date();
                    return nDate.getFullYear() - pDate.getFullYear();
                }
                // time = pDate.getFullYear() + "-";
                time = ("00" + (pDate.getMonth() + 1)).slice(-2) + "-";
                time += ("00" + pDate.getDate()).slice(-2) + " ";
                time += ("00" + pDate.getHours()).slice(-2) + ":";
                time += ("00" + pDate.getMinutes()).slice(-2) + ":";
                time += ("00" + pDate.getSeconds()).slice(-2)
            } else {
                pDate = new Date();
                time = ("00" + pDate.getHours()).slice(-2) + ":";
                time += ("00" + pDate.getMinutes()).slice(-2) + ":";
                time += ("00" + pDate.getSeconds()).slice(-2)
            }
            return time;
        }
        var nowDate = function (time) {
            if (typeof (time) != 'undefined') pDate = new Date(time * 1000);
            else pDate = new Date();
            time = pDate.getFullYear() + "-";
            time += ("00" + (pDate.getMonth() + 1)).slice(-2) + "-";
            time += ("00" + pDate.getDate()).slice(-2) + " ";
            time += ("00" + pDate.getHours()).slice(-2) + ":";
            time += ("00" + pDate.getMinutes()).slice(-2) + ":";
            time += ("00" + pDate.getSeconds()).slice(-2);
            return time;
        }
        //绑定需要 form提交的表单
        var formpost = function (dom) {
            console.log(dom);
            $('#' + dom + ' button').off('click');
            $('#' + dom + ' button').on('click', function () {
                var data = "{status:0,msg:'提交数据...'}";
                $('#consolelog').prepend('[' + now() +
                    '] <span class="jf-ObjectBrace">CLIENT</span> data:' + data + '<br />');
                $('pre').html(format(data));

                $('#' + dom + 'form').submit();
                $('#' + dom + 'iframe').off('load');
                $('#' + dom + 'iframe').on('load', function () {
                    try {
                        var data = JSON.parse($(this).contents().find('body').text());
                    } catch (e) {
                        // alert(e);
                        var data = "{status:0,msg:'上传失败.'}";
                    }
                    $('#consolelog').prepend('[' + now() +
                        '] <span class="jf-PropertyName">SERVER</span> data:' + JSON.stringify(
                            data) + '<br />');
                    $('pre').html(format(data));
                });
            });
        }


        $(function () {
            $(document).on('click', 'button[type="submit"]', function () {
                app.postdata();
            });

            $(document).on('click', 'a[data-toggle="tab"]', function () {
                var action = app.url + ($(this).attr('data-url') || '/');
                var name = $(this).text();
                var href = $(this).attr('href') + '';
                $(href + ' h5').text('[ ' + name + ' ] 相关参数：');
                $('#main_url').val(action);
            });
            $('#main_url').val(app.url);
            $('a[data-toggle="tab"]:first').click();

            $('#report_upload form').on('submit', function () {
                var data = "{status:0,msg:'提交数据...'}";
                $('#consolelog').prepend('[' + app.now() +
                    '] <span class="jf-ObjectBrace">CLIENT</span> data:' + data + '<br />');
                $('pre').html(format(data));
                $('#report_upload iframe').off('load');
                $('#report_upload iframe').on('load', function () {
                    try {
                        var data = JSON.parse($(this).contents().find('body').text());
                    } catch (e) {
                        var data = "{status:0,msg:'上传失败.'}";
                    }
                    $('#consolelog').prepend('[' + app.now() +
                        '] <span class="jf-ObjectBrace">CLIENT</span> data:' + data +
                        '<br />');
                    $('pre').html(format(data));
                });
            });
            formpost('address-add');
            formpost('address-update');
            formpost('order-add');
            formpost('order-arradd');
            //ws.onopen = function() {
            //		$('#consolelog').prepend('['+app.now()+'] <span class="jf-ObjectBrace">CLIENT</span> data:'+socketUrl+',连接成功.<br />');
            //};
            //ws.onmessage = function(e) {
            //    $('#consolelog').prepend('['+app.now()+'] <span class="jf-PropertyName">SERVER</span>:'+ e.data +'<br />');
            //};
        });
    </script>
</body>

</html>